package com.recipedb.recipedb.service.impl;

import com.recipedb.recipedb.entity.RecipeCommentLike;
import com.recipedb.recipedb.entity.RecipeCommentLikeId;
import com.recipedb.recipedb.repository.RecipeCommentLikeRepository;
import com.recipedb.recipedb.service.RecipeCommentLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;

@Service
public class RecipeCommentLikeServiceImpl implements RecipeCommentLikeService {

    @Autowired
    private RecipeCommentLikeRepository repository;

    @Override
    public RecipeCommentLike save(RecipeCommentLike entity) {
        return repository.save(entity);
    }

    @Override
    public void deleteById(RecipeCommentLikeId id) {
        repository.deleteById(id);
    }

    @Override
    public Optional<RecipeCommentLike> findById(RecipeCommentLikeId id) {
        return repository.findById(id);
    }

    @Override
    public List<RecipeCommentLike> findAll() {
        return repository.findAll();
    }

    // 实现：根据评论ID查询点赞记录
    @Override
    public List<RecipeCommentLike> findByCommentId(Long commentId) {
        return repository.findByCommentIdOrderByCreatedAtDesc(commentId);
    }


}
